
function fastRegSuccesscallBack(data){
    stop_round();
    $("#fast-reg-btn-box").html(data.data);
    if(data.noticeMsg != ""){
        layer.alert(data.noticeMsg, {icon: 6,title:"温馨提示"});
    }
}

function fastErrorCallBack(data){
    layer.msg(data.errorMsg,{time:3000,offset:0,shift: 6,icon:5});
    stop_round();
    comfirmBtn();
}

function doFastRegAction(obj){
    var o=$(obj),p={};var i=o.attr('data-id'),u=o.attr('data-url'),k=o.attr('data-key');
    p.plat=i,p.keyCode=k;
    start_round();
    cancelBtn(obj);
    doRequest(u,p,true,fastRegSuccesscallBack,fastErrorCallBack);
}

var timeround;
function start_round(){
    var angle = 0;
    timeround = setInterval(function(){
        angle +=15;
        $('#progress_bar').rotate(angle);
    }, 50);
}

function stop_round(){
    if(timeround != "undefined"){
        clearInterval(timeround);
    }
}
$(function(){
    $.fn.expr = function(){
        var _self = $(this);
        //未登录
        _self.find(".ulogin").on("click",function(){
            layer.msg("请先登录，再进行操作",{icon:0,offset:300,time:2000});return;
        });
        //没绑手机
        _self.find(".umobile").on("click",function(){
            layer.confirm("\u5148\u7ed1\u5b9a\u624b\u673a\u624d\u53ef\u4ee5\u4f53\u9a8c\u54e6",{btn:["\u9a6c\u4e0a\u53bb\u7ed1\u5b9a","\u518d\u7b49\u7b49"],offset:300,icon:0,title:"\u5c0f6\u63d0\u793a"},
            function(){
                window.open("/user/security.html#phone","_blank")
            },function(){});
            return;
        });
        //对接中
        _self.find(".uwork").on("click",function(){
            layer.msg("正在火速对接中，请耐心等待！",{icon:0,offset:300,time:2000});return;
        });
    }
    $("#_t_exp_div").expr();
    $.fn.imgshow = function() {
        this.each(function() {
            var l = $(this).find("img");
            var j = 0;
            var m = 0;
            var n = "";
            var i = "";
            l.click(function() {
                var k = "";
                l.each(function(e, d) {
                    $(d).attr("eq", e);
                    var c = $(this).attr("data-original");
                    if (!c) {
                            k += "<img src='" + $(this).attr("src") + "' />"
                    } else {
                            k += "<img src='" + c + "' />"
                    }
                });
                $(".img-group").html("");
                $(".img-group").html(k);
                i = ".img-group";
                $(".view-larger").show();
                n = $(this);
                m = parseInt(n.attr("eq"));
                j = l.length;
                $(i + " img")[m].onload = function() {
                    a(i, m, n.attr("title"))
                }
            });
            function a(v, h, c) {
                c = c || "";
                h += 1;
                var d = $(v + " img");
                $(v).show();
                //$(".title-status").html(c);
                $(".count-status").html(h + "/" + j);
                d.css({
                        display: "none",
                        width: "auto",
                        height: "auto"
                });
                d.eq(m).show();
                var u = d.eq(m).height();
                var f = d.eq(m).width();
                var e = $(window).height() - 100;
                var w = $(window).width() - 350;
                if (u > e) {
                        d.eq(m).height(e)
                } else {
                        if (f > w) {
                                d.eq(m).width(w)
                        }
                }
                var t = d.eq(m).height() / 2;
                var g = d.eq(m).width() / 2;
                $(v).stop(true, true).animate({
                        "margin-top": "-" + t + "px",
                        "margin-left": "-" + g + "px"
                }, 0)
            }
            $(".o-middle .left").click(function(e) {
                e.stopPropagation();
                if (m <= 0) {
                    return
                }
                m -= 1;
                a(i, m, n.attr("title"))
            });
            $(".o-middle .right").click(function(e) {
                e.stopPropagation();
                if (m >= j - 1) {
                    return
                }
                m += 1;
                a(i, m, n.attr("title"))
            });
            $(".view-larger .lager-colse").click(function(e) {
                e.stopPropagation();
                $("body").css("overflow", "auto");
                $(".view-larger").hide();
                $(".img-group").hide()
            })
            
            $(".overlay").on("mouseover",function(){
                $(this).css("cursor","url(../static/default/img/zoom_out.cur),auto");
            }).on("click",function(){
                $("body").css("overflow", "auto");
                $(".view-larger").hide();
                $(".img-group").hide()
            });
        })
    }  
    if(typeof($(".platform-data .pic-list")) == "object"){
        $(".platform-data .pic-list").imgshow();
    }
    $.fn.show_day_interest = function(){
        var _self = $(this);
        var C = _self.find(".show-inter");
        var P = $(".reward-popup-fat");
        var L = P.find(".popup-close");
        var show_data = function(data){
            var F = P.find(".fixed-award"),
                E = P.find(".extra-award"),
                dl = P.find("#day_list"),
                ls = data.list,
                H = "";
            F.text(data.info.fixed);
            E.text(data.info.extra);
            if(ls.length > 0){
                for(var i = 0 ;i < ls.length ;i++){
                    var D = ls[i];
                    H += "<tr><td>"+D.date_s+"</td><td>"+D.fixed+"</td><td>"+D.extra+"</td><td>"+D.total+"</td></tr>";
                }
            }else{
                H += "<tr><td colspan='4'><img src='../../static/default/img/no-trade.png'/></td></tr>";
            }
            dl.html(H);
            P.show();
        }
        var s = function(O){
            var iid = $(O).attr("data-iid");
            doRequest("/ajax/fetch_day_interests",{taskId:iid},false,function(resp){
                show_data(resp);
            },function(){});
        }
        C.on("click",function(){
            s(this);
        });
        L.on("click",function(){
            P.hide();
        });
    }
    $("#invest_list").show_day_interest();
    $.fn.income_board = function(){
        var _self = $(this),
            L = _self.find(".time-nav li"),
            P = _self.find(".time-nav p"),
            B = _self.find(".rank-list"),
            A = _self.delegate(".rank-list .care");
        var show_data = function(M){
            B.html("<span class='load-tag'></span>");
            doRequest("/ajax/fetch_user_income",{timeT:M},true,function(resp){
                B.html(resp.htmlData);
            },function(){});
            return;
        }
        L.on("click",function(){
            var T = $(this).attr("data-type"),
                I = $(this).index(),
                W = $(this).width() + 8;
            P.stop(false,true).animate({"left": I*W + 14 + "px"},300);
            show_data(T);
        });
        _self.delegate(".rank-list .care","click",function(){
            var U = $(this).attr("data-uuid"),
                V = $(this).attr("data-val"),
                B = $(this).find("b");
            if(is_login.uuid == 0){
                layer.msg("请先登录，再进行操作",{icon:0,offset:300,time:2000});return;
            }
            if(is_login.uuid == U){
                layer.msg("不能关注自己哦",{icon:0,offset:300,time:2000});return;
            }
            var _v = 1 - V;
            $(this).attr("data-val",_v);
            if(_v == 1){
                B.removeClass("icon-unlove").addClass("icon-loved");
                layer.msg("已关注",{icon:6,offset:300,time:1000});
            }else{
                B.removeClass("icon-loved").addClass("icon-unlove");
                layer.msg("已取消",{icon:6,offset:300,time:1000});
            }
            doRequest("/ajax/cancel_fan_act",{author_id:U,is_fan:_v},true,function(resp){
                
            },function(resp){
                layer.msg(resp.errorMsg,{icon:0,offset:300,time:2000});return;
            });
        });
        
        show_data("m");
    }
    if(typeof($("#income-rank-box")) == "object"){
        $("#income-rank-box").income_board();
    }
    $.fn.show_plats_working = function(){
        var _self = $(this),
            a = _self.find(".limit"),
            li = _self.find("li"),
            box = $("#container-plats-working"),
            N = $(".null-container");
        var C = function(l){
            l.each(function(index,obj){
                $(this).css("margin","0 15px 15px 0");
                if((index+1)%2 == 0){
                    $(this).css("margin-right",0);
                }
            });
        }
        var B = function(T){
            var L = box.find("li");
            if(T == ""){
                return L.attr('data-status',1).show(),N.hide(),C(L);
            }
            if((box.find("."+T))[0] == undefined){
                return L.attr('data-status',0).hide(),N.show();
            }
            L.each(function(index,obj){
                if($(this).hasClass(T)){
                    $(this).attr('data-status',1).show();
                }else{
                    $(this).attr('data-status',0).hide();
                }
            });
            var _L = box.find("li[data-status='1']");
            return C(_L),N.hide();
        }
        a.on("click",function(){
            a.addClass("active");li.removeClass("active");
            return B("");
        });
        li.on("click",function(){
            var t = ($(this).find("span")).attr("data-type");
            a.removeClass("active");
            $(this).addClass("active").siblings().removeClass("active");
            return B(t);
        });
    }
    $("#options-type").show_plats_working();
    
    
    $.fn.container_plats_list = function(){
        var _self = $(this),
            $li = _self.find(".img-btn ul li");
        _self.find(".container-plats-list").find("ul:first").addClass("active");
        _self.find(".container-plats-list:first").addClass("active");
        var M = function(index,B,imgWidth){
            var dl = B.find(".list");
            dl.animate({
                marginLeft : -imgWidth*(index) + 'px'
            },1000,function(){});
        }
        var F = function(B){
            var N = B.find("ul").length,
            L = B.find(".prev"),
            R = B.find(".next"),
            W = B.find("ul").width();
            B.find(".list").css("margin-left",0);
            B.find(".list div ul:first").addClass("active");
            L.unbind("click").on("click",function(){
                var ul = B.find(".list div ul.active"),
                    i = ul.index();
                if(i == 0){
                    return;
                }
                ul.removeClass("active").prev().addClass("active");
                return M(i-1,B,W);
            });
            R.unbind("click").on("click",function(){
                var ul = B.find(".list ul.active"),
                    i = ul.index();
                if((i+1) == N){
                    return;
                }
                ul.removeClass("active").next().addClass("active");
                return M(i+1,B,W);
            });
        }
        
        $li.mouseenter(function(){
            var i = $(this).index();
            $(this).addClass('active').siblings().removeClass('active');
            $(this).parents('.plat-screening').find('.container-list').eq(i).addClass("active").fadeIn().siblings('.container-list').removeClass("active").hide();
            return F(_self.find(".container-plats-list.active"));
        });
        return F(_self.find(".container-plats-list.active"));
    }
    if(($(".plat-screening"))[0] !== undefined){
        $(".plat-screening").container_plats_list();
    }
    
    $.fn.check_classify_data = function(){
        var _self = $(this),
            c = _self.find(".classify");
        var ts = "",
            no_r = $(".on-result-box");
        var F = function(pageIndex){
            pageIndex = typeof(pageIndex) == "undefined" ? 0 : pageIndex;
            var containerId = "plats_list_pagination";
            $("#load-plats-box").html("<span class='load-tag'></span>");
            doRequest("/ajax/get_plat_json",{pageIndex:pageIndex,types:ts,stamptime:Math.random()},true,function(resp){
                var totalCount = resp.data.totalCount;
                var str = "";
                if(totalCount == 0){
                    str += "";no_r.show();
                }else{
                    var htmlData = resp.data.htmlData;
                    str += htmlData;no_r.hide();
                }
                $(".search-result span").text(totalCount);
                $("#load-plats-box").html(str);
                setTimeout(function(){
                    createPaginationModel({containerId:containerId,perNum:15,currIndex:resp.data.pageIndex,totalCount:totalCount,num:6,flag:false},F);
                },30);
            },function(data){});
        }
        
        var load = function(){
            var C = _self.find(".classify.checked");
            ts = "";
            C.each(function(){
                ts += $(this).attr("data-id")+",";
            });
            ts = ts.substr(0,ts.length-1);
            return F();
        }
        
        c.on("click",function(){
            var div = $(this).parents("div.classify-p");
            div.find(".classify").removeClass("checked");
            $(this).addClass("checked");
            return load();
        });
        $(".reset-type input").on("click",function(){
            $(".classify").removeClass("checked");
            $(".unlimit-type").addClass("checked");
            return load();
        });
        return load();
    }
    
    $.fn.seach_plat = function(){
        var _self = $(this),
            _input = _self.find(".left-search input"),
            _bn = _self.find("button"),
            _box = _self.find("#seach-result-box"),
            val = "";
        var F = function(input){
            val = input.val();
            if(val == ""){_box.hide();return;}
            _box.show().html("<span class='load-tag' style='height:25px;'></span>");
            doRequest("/ajax/get_plat_seach",{keyStr:val},true,function(res){
                var html = res.seachRes;
                if(html == ""){
                    _box.html("<span class='empty no-result'>查无结果</span>");
                }else{
                    setTimeout(function(){
                        _box.html("").html(html);
                    },500);
                }
            },function(res){});
        }
        var move = function(code){
            _box.focus();
            var tar = _box.find("a");
            if(tar[0] === undefined){return;}
            index = _box.find("a.active").index();
            num = 0;
            if(code == 38){
                if(index < 1){return;}
                num = index - 1;
            }else if(code == 40){
                if((index+1) == tar.length){return;}
                num = index + 1;
            }
            var obj = tar.eq(num);
            obj.addClass("active").siblings().removeClass("active");
            _box.scrollTop(obj[0].scrollHeight * num);
        }
        
        _input.on("keyup",function(e){
            if(e.keyCode == 38 || e.keyCode == 40){
                move(e.keyCode);return;
            }else if(e.keyCode == 13){
                if((_box.find("a.active"))[0] !== undefined){
                    window.open(_box.find("a.active").attr("href"));
                    return;
                }else{
                    return F(_input);
                }
            }
            return F(_input);
        }).on("focus",function(){
            return _box.show();
        }).on("click",function(e){
            return e.stopPropagation();
        });  
        _bn.on("click",function(e){
            e.stopPropagation();
            return F(_input);
        });
        $(document.body).on("click",function(){
            return _box.hide();
        })
        
    }
    
    if(($(".classify-all"))[0] !== undefined){
        $(".classify-all").check_classify_data();
        $(".search-plat-box").seach_plat();
    }
});